/* 文本对比工具 - 支持浅色/深色主题 */

/* ========== CSS 变量定义 ========== */
:root {
    /* 浅色主题（默认） */
    --bg-primary: #ffffff;
    --bg-secondary: #f5f5f5;
    --bg-tertiary: #e8e8e8;
    --text-primary: #333333;
    --text-secondary: #666666;
    --border-color: #d0d0d0;
    --border-color-light: #e0e0e0;
}

/* 深色主题 */
body.dark-theme,
.dark-theme {
    --bg-primary: #1e1e1e;
    --bg-secondary: #252526;
    --bg-tertiary: #2d2d30;
    --text-primary: #d4d4d4;
    --text-secondary: #858585;
    --border-color: #3e3e42;
    --border-color-light: #2d2d30;
}

.text-comparator {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
}

/* ========== 差异显示区域 ========== */
.diff-display-container {
    flex: 0 0 60vh;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-bottom: 2px solid var(--border-color);
    background: var(--bg-primary);
}

.diff-header {
    display: flex;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.diff-column-header {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 8px 12px;
    gap: 6px;
}

.diff-column-header:first-child {
    border-right: 1px solid var(--border-color);
}

.diff-toolbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.diff-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.diff-stats {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
}

.stat-item {
    color: var(--text-secondary);
}

.stat-added {
    color: #3fb950;
    font-weight: 600;
}

.stat-removed {
    color: #f85149;
    font-weight: 600;
}

.stat-modified {
    color: #ffc107;
    font-weight: 600;
}

/* Merge All 按钮 */
.btn-secondary {
    padding: 6px 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-secondary:hover {
    background: var(--border-color);
    opacity: 0.9;
}

.btn-secondary:active {
    opacity: 0.8;
}

.merge-to-changed,
.merge-to-original {
    font-size: 11px;
    padding: 5px 10px;
}

/* 差异内容区域 */
.diff-content-wrapper {
    flex: 1;
    display: flex;
    min-height: 0;
    overflow: hidden;
}

.diff-column {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 13px;
    line-height: 20px;
    background: var(--bg-primary);
}

.diff-column:first-child {
    border-right: 1px solid var(--border-color);
}

/* 差异行样式 */
.diff-line {
    display: flex;
    min-height: 20px;
    position: relative;
    align-items: flex-start;
}

.diff-line-number {
    flex: 0 0 50px;
    padding: 0 8px;
    text-align: right;
    color: var(--text-secondary);
    background: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    user-select: none;
    font-size: 12px;
    line-height: 20px;
}

.diff-line-content {
    flex: 1;
    padding: 0 12px;
    white-space: pre-wrap !important;
    word-wrap: break-word !important;
    overflow-wrap: break-word !important;
    word-break: break-word;
    max-width: 100%;
    overflow-x: hidden;
}

/* 差异类型颜色 */
.diff-line.added {
    background: rgba(63, 185, 80, 0.2);
}

.diff-line.added .diff-line-number {
    background: rgba(63, 185, 80, 0.2);
}

.diff-line.removed {
    background: rgba(248, 81, 73, 0.2);
}

.diff-line.removed .diff-line-number {
    background: rgba(248, 81, 73, 0.2);
}

.diff-line.modified {
    background: rgba(255, 193, 7, 0.2);
}

.diff-line.modified .diff-line-number {
    background: rgba(255, 193, 7, 0.2);
}

.diff-line.equal {
    background: var(--bg-primary);
}

.diff-line.empty {
    background: var(--bg-secondary);
}

.diff-line.empty .diff-line-number {
    background: var(--bg-secondary);
}

/* 字符级差异高亮 */
.diff-char {
    background: rgba(255, 193, 7, 0.5);
    padding: 0 2px;
    border-radius: 2px;
}

.diff-line.added .diff-char {
    background: rgba(63, 185, 80, 0.5);
}

.diff-line.removed .diff-char {
    background: rgba(248, 81, 73, 0.5);
}

/* ========== 编辑器区域 ========== */
.editors-container {
    flex: 1;
    display: flex;
    min-height: 0;
}

.text-input-section,
.text-output-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.text-input-section {
    border-right: 1px solid var(--border-color);
}

/* 编辑器头部 */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.section-header h1 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
    color: var(--text-primary);
}

.section-header .actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* 排序下拉菜单 */
.sort-dropdown-container {
    position: relative;
}

.sort-btn {
    display: flex;
    align-items: center;
    gap: 6px;
}

.dropdown-arrow {
    font-size: 10px;
    transition: transform 0.2s;
}

.sort-dropdown-container.open .dropdown-arrow {
    transform: rotate(180deg);
}

.sort-dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    margin-top: 4px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    min-width: 150px;
}

.sort-dropdown-menu.show {
    display: block;
}

.sort-option {
    padding: 8px 12px;
    font-size: 12px;
    color: var(--text-primary);
    cursor: pointer;
    transition: background 0.2s;
}

.sort-option:hover {
    background: var(--bg-tertiary);
}

.sort-option:first-child {
    border-radius: 4px 4px 0 0;
}

.sort-option:last-child {
    border-radius: 0 0 4px 4px;
}

/* 按钮样式 */
.btn-primary {
    padding: 6px 16px;
    background: #0e639c;
    color: white;
    border: none;
    border-radius: 4px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-primary:hover {
    background: #1177bb;
}

.btn-primary:active {
    background: #0d5a8f;
}

/* 文本编辑器 */
.input-editor {
    flex: 1;
    padding: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    border: none;
    outline: none;
    font-family: 'Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', monospace;
    font-size: 13px;
    line-height: 20px;
    resize: none;
}

.input-editor::placeholder {
    color: var(--text-secondary);
}

.input-editor:focus {
    background: var(--bg-secondary);
}

/* ========== 滚动条样式 ========== */
.diff-column::-webkit-scrollbar,
.input-editor::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.diff-column::-webkit-scrollbar-track,
.input-editor::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.diff-column::-webkit-scrollbar-thumb,
.input-editor::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 5px;
}

.diff-column::-webkit-scrollbar-thumb:hover,
.input-editor::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* ========== Toast 通知样式 ========== */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: 6px;
    color: white;
    font-size: 14px;
    font-weight: 500;
    z-index: 10000;
    opacity: 0;
    transform: translateY(-20px);
    transition: all 0.3s ease;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

.toast-success {
    background: #28a745;
}

.toast-error {
    background: #dc3545;
}

.toast-info {
    background: #007bff;
}

.toast-warning {
    background: #ffc107;
    color: #212529;
}

/* ========== 响应式设计 ========== */
@media (max-width: 1200px) {
    .section-header .actions {
        gap: 6px;
    }
    
    .btn-secondary,
    .btn-primary {
        padding: 5px 10px;
        font-size: 11px;
    }
}

@media (max-width: 768px) {
    .diff-display-container {
        flex: 0 0 50vh;
    }
    
    .section-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 8px;
    }
    
    .section-header .actions {
        width: 100%;
        justify-content: flex-start;
        flex-wrap: wrap;
    }
}

/* ========== 辅助功能 ========== */
.btn-secondary:focus,
.btn-primary:focus,
.sort-option:focus {
    outline: 2px solid #0e639c;
    outline-offset: 2px;
}

.input-editor:focus {
    outline: 2px solid #0e639c;
    outline-offset: -2px;
}

/* ========== 加载指示器 ========== */
.loading-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 20px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 3px solid var(--border-color);
    border-top-color: #0e639c;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}
